import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.*;


public class TCPConnection{
	int port = 6543;
	public String ipAdd;
	public boolean server;
	public Socket mySocket;
	public InputStream is;
	public OutputStream os;
	public Vector data = new Vector();
	
	public TCPConnection(boolean s,String ia,int p){
		ipAdd = ia;
		server = s;
		port = p;
		connect();
	}
	
	public void connect(){
		if(server) mySocket = new TCPServer().getSocket();
		else mySocket = new TCPClient(ipAdd).getSocket();
		try{
			is = mySocket.getInputStream();
			os = mySocket.getOutputStream();
		}catch(Exception e){System.out.println(e);}
		new Thread(new TCPReceiver(is,data)).start();
	}
	
	
	
	public void send(String msg){
		try { 
			char[] msgBuf = msg.toCharArray();
			String strBuf = new String(msgBuf);
			while(strBuf.length()<20) strBuf += '#';
			os.write(strBuf.getBytes());
		}catch (IOException ioe) {System.out.println( ioe );} 
	}
}
